package com.guang.interupt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author lg
 * @Description 线程对于睡眠(sleep)中的线程操作
 * @date 2022/10/17 11:37
 *
 *
 * 总结：中断睡眠着的线程会造成异常出现，然后JVM会自动的将当前的线程中断标记置为false
 *      由程序员来进行指定操作
 *
 */
public class ThreadInteruptOne {

    private static Logger logger = LoggerFactory.getLogger(ThreadInteruptOne.class);

    public static void main(String[] args) {
        Thread sleepThread = new Thread(() -> {
            try {
                logger.info("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
                logger.info("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
                Thread.sleep(1000);
                logger.info("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
            } catch (InterruptedException e) {
                e.printStackTrace();
                logger.error("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
                logger.error("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
            }
        }, "sleep");
        sleepThread.start();
        sleepThread.interrupt();
    }
}
